﻿Public Class fTipoCliente
    Dim daTipoCli As lbGlobalcom.dsTerceroTableAdapters.TER_TIPOCLIENTESTableAdapter
    Dim daClave As lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
    Private Sub btnCargaClientes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCargaClientes.Click
        Try
            If DsTercero.TER_TIPOCLIENTES.GetChanges IsNot Nothing Then
                TER_TIPOCLIENTESBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daTipoCli.Update(DsTercero.TER_TIPOCLIENTES)
                End If
            End If
            daTipoCli.Fill(DsTercero.TER_TIPOCLIENTES)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fTipoCliente_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Try
            If DsTercero.TER_TIPOCLIENTES.GetChanges IsNot Nothing Then
                TER_TIPOCLIENTESBindingSource.EndEdit()
                If MessageBox.Show("Hay cambios pendientes por salvar, desea salvarlos", "Cambios Pendientes", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                    daTipoCli.Update(DsTercero.TER_TIPOCLIENTES)
                End If
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub fTipoCliente_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            daTipoCli = New lbGlobalcom.dsTerceroTableAdapters.TER_TIPOCLIENTESTableAdapter
            daClave = New lbGlobalcom.dsGlobalTableAdapters.GLO_CLAVESPRIMARIASTableAdapter
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub TER_TIPOCLIENTESBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TER_TIPOCLIENTESBindingNavigatorSaveItem.Click
        Try
            Validate()
            TER_TIPOCLIENTESBindingSource.EndEdit()
            daTipoCli.Update(DsTercero.TER_TIPOCLIENTES)
            MessageBox.Show("Se salvarón resgistros de Tipo Clientes con exito", "Salva Tipo Clientes", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
    End Sub

    Private Sub BindingNavigatorDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorDeleteItem.Click
        Try
            If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
                TER_TIPOCLIENTESBindingSource.Remove(TER_TIPOCLIENTESBindingSource.Current)
                daTipoCli.Update(DsTercero.TER_TIPOCLIENTES)
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try
        
    End Sub

    Private Sub TER_TIPOCLIENTESDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles TER_TIPOCLIENTESDataGridView.CellBeginEdit
        If e.ColumnIndex = 1 AndAlso TER_TIPOCLIENTESDataGridView.Rows(e.RowIndex).Cells(0).Value Is DBNull.Value Then
            Dim dt As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASDataTable
            dt = daClave.GetDataByIdClavePrimaria("TER_TIPOCLIENTES")
            If dt.Count Then
                Dim dr As lbGlobalcom.dsGlobal.GLO_CLAVESPRIMARIASRow
                dr = dt.Rows(0)
                Dim Cons As lbGlobalcom.ConsecTablas = New lbGlobalcom.ConsecTablas(dr("TABLA"), dr("CAMPO"), dr("LONGITUD"))
                TER_TIPOCLIENTESDataGridView.Rows(e.RowIndex).Cells(0).Value = Cons.NumeroConsec
                Cons = Nothing
                TER_TIPOCLIENTESBindingSource.EndEdit()
                daTipoCli.Update(DsTercero.TER_TIPOCLIENTES)
            End If
        End If
    End Sub

    Private Sub TER_TIPOCLIENTESDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles TER_TIPOCLIENTESDataGridView.DataError
        MessageBox.Show(e.Exception.Message)
    End Sub

    Private Sub TER_TIPOCLIENTESDataGridView_UserDeletedRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowEventArgs) Handles TER_TIPOCLIENTESDataGridView.UserDeletedRow
        Try
            daTipoCli.Update(DsTercero.TER_TIPOCLIENTES)
            MessageBox.Show("Se elimino registro con exito", "Elimina Registro", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Samuel")
        End Try

    End Sub

    Private Sub TER_TIPOCLIENTESDataGridView_UserDeletingRow(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowCancelEventArgs) Handles TER_TIPOCLIENTESDataGridView.UserDeletingRow
        If MessageBox.Show("Esta seguro que desea eliminar este registro", "Elimina Registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.No Then
            e.Cancel = True
        End If
    End Sub
End Class